﻿Imports QLTHUVIEN.DTO
Public Class NhanVienDAO
    Public Function layNhanVien() As DataTable
        Dim strSql As String = "SELECT NV.MaNhanVien, NV.TenNhanVien, NV.DiaChi, NV.NgaySinh, NV.Email, NV.DienThoai, NV.TenDangNhap, NV.MatKhau, BC.TenBangCap, BP.TenBoPhan, CV.TenChucVu FROM NHANVIEN NV, BANGCAP BC, BOPHAN BP, CHUCVU CV WHERE NV.isDelete='False' AND NV.MaBangCap = BC.MaBangCap AND NV.MaBoPhan = BP.MaBoPhan AND NV.MaChucVu = CV.MaChucVu"
        Dim dt As DataTable = DataProvider.ExecuteQuery(strSql)
        Return dt
    End Function

    Public Function layNhanVienBoPhan(ByVal strTenBoPhan As String) As DataTable
        Dim strSql As String = "SELECT NV.MaNhanVien, NV.TenNhanVien FROM NHANVIEN NV, BOPHAN BP WHERE NV.MaBoPhan = BP.MaBoPhan and NV.isDelete ='False' and BP.TenBoPhan = N'" & strTenBoPhan & "'"
        Dim dt As DataTable = DataProvider.ExecuteQuery(strSql)
        Return dt
    End Function

    Public Sub ThemNhanVien(ByVal nhanVienDto As NhanVienDTO)
        Dim strSql As String = "INSERT INTO NHANVIEN(TenNhanVien, DiaChi, NgaySinh, Email, DienThoai, TenDangNhap, MatKhau, MaBangCap, MaBoPhan, MaChucVu) VALUES(N'" & nhanVienDto.TenDangNhap & "',N'" & nhanVienDto.DiaChi & "','" & nhanVienDto.NgaySinh & "','" & nhanVienDto.Email & "','" & nhanVienDto.DienThoai & "','" & nhanVienDto.TenDangNhap & "','" & nhanVienDto.MatKhau & "', " & nhanVienDto.MaBangCap & ", " & nhanVienDto.MaBoPhan & ", " & nhanVienDto.MaChucVu & ")"
        DataProvider.ExecuteQuery(strSql)
    End Sub

    Public Sub SuaNhanVien(ByVal nhanVienDto As NhanVienDTO)
        Dim strSql As String = "UPDATE NHANVIEN SET TenNhanVien =N'" & nhanVienDto.TenNhanVien & "', DiaChi=N'" & nhanVienDto.DiaChi & "', NgaySinh='" & nhanVienDto.NgaySinh & "', Email='" & nhanVienDto.Email & "', DienThoai='" & nhanVienDto.DienThoai & "', TenDangNhap='" & nhanVienDto.TenDangNhap & "', MatKhau='" & nhanVienDto.MatKhau & "', MaBangCap=" & nhanVienDto.MaBangCap & ", MaBoPhan=" & nhanVienDto.MaBoPhan & ", MaChucVu=" & nhanVienDto.MaChucVu & " WHERE MaNhanVien =" & nhanVienDto.MaNhanVien
        DataProvider.ExecuteQuery(strSql)
    End Sub

    'xoa nhan vien dat thuoc tinh isDelete = True
    Public Sub XoaNhanVien(ByVal nhanVienDto As NhanVienDTO)
        Dim strSql As String = "UPDATE NHANVIEN SET isDelete ='" & nhanVienDto.IsDelete.ToString() & "' WHERE MaNhanVien =" & nhanVienDto.MaNhanVien
        DataProvider.ExecuteQuery(strSql)
    End Sub
End Class
